package com.pureut.storage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.storage.domain.SalesReturnDetail;
import com.pureut.storage.dto.SalesReturnDetailDto;
import com.pureut.storage.dto.SubcontractReceiptDetailDto;
import com.pureut.storage.mapper.SalesReturnDetailMapper;
import com.pureut.storage.service.SalesReturnDetailService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/***
 * 销售退货实现层
 * Author:C
 * Date:2023/01/29 8:52
 * @DESC
 */
@Service
public class SalesReturnDetailServiceImpl extends ServiceImpl<SalesReturnDetailMapper, SalesReturnDetail> implements SalesReturnDetailService {
    /**
     * 销售退货mapper
     */
    @Resource
    SalesReturnDetailMapper salesReturnDetailMapper;

    /**
     * 销售退货明细列表
     * @param id
     * @return
     */
    @Override
    public List<SalesReturnDetailDto> getSalesReturnDetail(long id) {
        //获取网型标准缓存字典数据
        List<SysDictData> netArray = DictUtils.getDictCache("sys_of_type");
        Map<String, String> netMap = netArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        //获取铺网类型标准缓存字典数据
        List<SysDictData> netTypeArray = DictUtils.getDictCache("sys_type_net");
        Map<String, String> netTypeMap = netTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        List<SysDictData> statusArray = DictUtils.getDictCache("miscellaneous_receipt_detail_status");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        List<SalesReturnDetailDto> salesReturnDetailDtoList = salesReturnDetailMapper.getSalesReturnDetailList(id);

        for (SalesReturnDetailDto entity : salesReturnDetailDtoList) {
            entity.setMaterialNetDict(netMap.get(entity.getMaterialNet()));
            entity.setMaterialNetTypeDict(netTypeMap.get(entity.getMaterialNetType()));
            entity.setStatusDict(statusMap.get(entity.getStatus()));
        }
        return salesReturnDetailDtoList;

    }
}
